package com.example.test.interfaces.facade;

import com.example.test.applicaiton.services.ArticleService;
import com.example.test.domain.entity.ArticleModel;
import org.springframework.web.bind.annotation.*;
import com.example.test.infrastructre.utils.OutData;

// 能听到我说话嘛
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleFacade {
    @Resource
   private ArticleService articleService;

    //书籍列表接口，搜索条件（类目、标题模糊搜索）
    @GetMapping("findArticleList")
    public OutData<List<ArticleModel>>getBookList(String title, String categoryName) {
        List<ArticleModel> result =  articleService.selectAll(title, categoryName);
        return new OutData<>(result);
    }

    //添加书籍接口
    @PostMapping("addArticle")
    public OutData addArticle(@RequestBody ArticleModel article) {
        //todo 验证分类是否存在
//        article.setAdd_time(System.currentTimeMillis() / 1000);
        int result = articleService.addArticle(article);
        return  new OutData<>(result);
    }

    //编辑接口
    @PutMapping("updateArticle")
    public OutData updateArticle(@RequestBody ArticleModel article) {
        int result = articleService.updateArticleById(article);
        return new OutData<>(result);
    }

    //删除接口
    @DeleteMapping("deleteArticle")
    public OutData deleteArticle(@RequestParam long articleId) {
        int result = articleService.deleteArticleById(articleId);
        return new OutData<>(result);
    }
}
